<!--登录-->
<div class="login">
    <form method="post" action="">
    <dl>
        <dt><p class="p1">二狐账号登录</p></dt>
        <dd>
             <div class="text_ico user"></div>
             <div class="metext"><input type="text" id="username" class="user_tx" name="username" placeholder="请输入用户名/手机号码"/></div>
        </dd>
        <dd>
             <div class="text_ico password"></div>
             <div class="metext"><input type="password" id="password" class="user_tx" name="password" placeholder="请输入密码"/></div>
        </dd>
        <dt><p class="p2"><a href="#" class="a1">忘记密码？</a></p></dt>
        <dt>
             <a href="<?=Yii::$app->urlManager->createUrl('/user/register')?>" class="a2">注册</a>
             <input type="hidden" name="_csrf" id="_csrf" value="<?=\Yii::$app->request->csrfToken; ?>" />
             <input type="button" class="login_bt" value="登录" />
        </dt>
    </dl>
    </form>
</div>

<script type="text/javascript">
$(".login_bt").click(function() {
    login();
});

$('#password,#username').keydown(function(e) {
    if (e.keyCode == 13) {
    	if($("#password").val()!='' && $("#username").val()!=''){
    		login();
    	}
    }
});

function go(){
	window.location='/';
	//window.history.go(-1);
}

//登录
function login() {
    var username = $.trim($("#username").val());
    var password = $.trim($("#password").val());
    var _csrf = $.trim($("#_csrf").val());

    if (username && password) {
        $.ajax({
            type: 'POST',
            url: "<?=Yii::$app->urlManager->createUrl('/user/login');?>",
            data: { username : username, password : password, _csrf : _csrf },
            dataType: 'json',
            success: function(data) {
				$('body').append(data.ucsynlogin);
				setTimeout(function(){ go(); }, 3000);
            },
            error: function(xhq) {
            	alert(xhq.responseText);
            }
        });
    }
}
</script>